class Solution(object):
    def smallestRangeII(self, nums, k):
        nums.sort()
        n = len(nums)
        mi = nums[0]
        ma = nums[-1]
        ans = ma - mi
        for i in range(n - 1):
            a = nums[i]
            b = nums[i + 1]
            ans = min(ans, max(ma - k, a + k) - min(mi + k, b - k))
        return ans


data = Solution()
nums = [1, 3, 6]
k = 3
print(data.smallestRangeII(nums, k))
